library TreeRevive requires DestructableRevival

    struct TreeRevive extends array
        private static method extendTimeStructureFilter takes nothing returns boolean
            return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)
        endmethod

        private static method extendTimeUnitFilter takes nothing returns boolean
            return not IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)
        endmethod

        private static method getRevivalExtendTime takes destructable whichDest returns real
            local real x = GetDestructableX(whichDest)
            local real y = GetDestructableY(whichDest)
            if GetClosestUnitInRange(x, y, 300.0, Filter(function thistype.extendTimeUnitFilter)) != null then
                return 4.0
            endif

            if GetClosestUnitInRange(x, y, 40.0, Filter(function thistype.extendTimeStructureFilter)) != null then
                return 4.0
            endif
            return 0.0
        endmethod

        private static method getRevivalDelay takes destructable whichDest returns real
            return 90.0
        endmethod

        private static method shouldRevive takes destructable whichDest returns boolean
            return IsDestructableTree(whichDest)
        endmethod

        static method init takes nothing returns nothing
            call SetDestructableRevivalFilter(thistype.shouldRevive)
            call SetDestructableRevivalDelayGeter(thistype.getRevivalDelay)
            call SetDestructableRevivalRemainingGeter(thistype.getRevivalExtendTime)
        endmethod
    endstruct

endlibrary
